<div class="ibox float-e-margins">
    <div class="ibox-content" style="display: block;">
        <div class="row">
            <div class="col-md-6">
                <div class="btn-group">
                    <a class="btn btn-primary " href="{{route('admin.shop.list.city.curd')}}">添加城市</a>
                </div>
                <form method="get" action="">
                    <div class="input-group search_text">
                        <input type="text" name="name" placeholder="城市名称"
                               value="{{!empty(request('name'))?request('name'):''}}" class=" form-control">
                        <span class="input-group-btn">
                                <button type="submit" class="btn btn-primary">查找</button>
                            </span>
                    </div>
                </form>
            </div>
        </div>
        <div style="clear: both;"></div>
        <div class="hr-line-dashed"></div>
        <table class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>城市名称</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @if (!empty($data))
                @foreach ($data as $v)
                    <tr>
                        <td>{!! $v->name !!}</td>
                        <td>
                            <a href="{!!route('admin.shop.list.city.curd', ['id' => $v->id])!!}"
                               class="btn btn-xs btn-primary"><i class="fa fa-pencil" data-toggle="tooltip"
                                                                 data-placement="top" title=""
                                                                 data-original-title="编辑"></i></a>
                            <a class="btn btn-xs btn-danger" style="cursor:pointer;"
                               onclick="del_city({!!$v -> id!!});"><i class="fa fa-trash" data-toggle="tooltip"
                                                                      data-placement="top" title=""
                                                                      data-original-title="删除"></i></a>
                        </td>
                    </tr>
                @endforeach
            @endif
            <meta name="csrf-token" content="{{ csrf_token() }}">
            </tbody>
        </table>
        {!! $data->render() !!}
        <div class="pull-right">
        </div>
        <div class="clearfix"></div>
    </div>
</div>


<script>
    function del_city(id) {

        swal({
            title: "确定删除此项？会影响门店列表功能",
            text: "",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            cancelButtonText: "取消",
            closeOnConfirm: false,
        }, function () {
            $.ajax({
                type: 'POST',
                url: "{!!route('store.ajax.del')!!}",
                data: {'id': id, 'type': 'city'},
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    if (200 == data.code) {
                        swal({
                            title: "删除成功！",
                            text: "",
                            type: "success"
                        }, function () {
                            location = '{{route('admin.shop.list.city')}}';
                        });
                    } else {
                        swal("删除失败！", data.message, 'warning');
                    }
                }
            });
        });

    }
</script>